<template>

    <div class="header">
        <div class="left">
            <div class="back" @click="back()">返回</div>
        </div>
        <div class="title">历史记录</div>
    </div>
    <div class="body">
        <div v-if="list.length > 0" style="width: 100%;">
            <div class="item" v-for="item in list" :key="item._id">
                <!-- <span>{{ `${item.username} 在 ${item.updateTime} 修改了 ${item.imgname}` }}</span> -->
                <span>{{ item.username }}</span>在
                <span>{{ item.updateTime }}</span>修改了
                <span>{{ item.imgname }}</span>图片
            </div>
        </div>
        <div v-else style="width: 100%;">
            <div class="none">暂无历史记录</div>
        </div>
    </div>

</template>

<script setup>
import { ref, reactive, onMounted, nextTick } from 'vue'
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const back = () => {
    router.back()
}
//获取历史记录
onMounted(() => {
    const imgname = route.query.imgname
    nextTick(() => {
        if (imgname) {
            getHistory(imgname)
        } else {
            getHistory()
        }

    })
})

import request from '../utils/request';

let list = reactive([])

const getHistory = async (imgname) => {
    let res = {};
    if (imgname) {
        let req = {
            imgname: imgname
        }
        res = await request.get("/history", { params: req });
        Object.assign(list, res.data);
    } else {
        res = await request.get("/history");
    }

    Object.assign(list, res.data);
}
</script>
<style scoped lang='less'>
.header {
    width: 100%;
    height: 10vh;
    text-align: center;
    position: relative;
    background: skyblue;
    color: #fff;

    .left {
        position: absolute;
        top: 50%;
        left: 1vw;
        transform: translateY(-50%);
        display: flex;

        .back {
            padding: 1vw;
            font-size: 1rem;
            margin-left: 1vw;
            background-color: #fff;
            color: #000;
            transition: all .3s;

            &:hover {
                cursor: pointer;
                transform: translateX(-2px);
            }
        }
    }

    .title {
        font-size: 2rem;
        line-height: 10vh;
    }
}

.body {
    width: 100%;

    &>div {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;

        .item {
            width: 80%;
            height: 10vh;
            background-color: #fff;
            margin: 1vw;
            display: flex;
            justify-content: center;
            align-items: center;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            font-size: 20px;

            span {
                color: red;
                margin: 0 1vw;
            }
        }
    }

    .none {
        font-size: 30px;
        color: gray;
        margin-top: 4vw;
    }
}
</style>